<html>
<head>
<script src="../../resources/js-test.js"></script>
<style id="style" media="screen">
.non-existent-class {
    color: rgb(0, 0, 0);
}
</style>
</head>
<body>
<script>

if (window.testRunner)
    testRunner.waitUntilDone();

function classString(node)
{
    if (!node)
        return "[null]";
    var string = Object.prototype.toString.apply(node);
    return string.substr(8, string.length - 9);
}

function tagClassString(tagName)
{
    return classString(document.createElement(tagName));
}

function tagPrototypeClassString(tagName)
{
    return classString(document.createElement(tagName).__proto__);
}

function tagConstructorClassString(tagName)
{
    return classString(document.createElement(tagName).constructor);
}

function tagConstructorName(tagName)
{
    return document.createElement(tagName).constructor.name;
}

function testTag(tagName, className, prototypeName, constructorName)
{
    if (!prototypeName)
        prototypeName = className + "Prototype";
    if (!constructorName)
        constructorName = className;
    shouldBeEqualToString("tagClassString('" + tagName + "')", className);
    shouldBeEqualToString("tagPrototypeClassString('" + tagName + "')", prototypeName);
    shouldBeEqualToString("tagConstructorClassString('" + tagName + "')", "Function");
    shouldBeEqualToString("tagConstructorName('" + tagName + "')", constructorName);
}

function test(expression, className, prototypeName, constructorName)
{
    if (!prototypeName)
        prototypeName = className + "Prototype";
    if (!constructorName)
        constructorName = className;
    shouldBeEqualToString("classString(" + expression + ")", className);
    shouldBeEqualToString("classString(" + expression + ".__proto__)", prototypeName);
    shouldBeEqualToString("classString(" + expression + ".constructor)", "Function");
    shouldBeEqualToString(expression + ".constructor.name", constructorName);
}

function runTest()
{
    description("This tests wrapper class names for JavaScript.");

    stylesheet = document.getElementById("style").sheet;
    root = document.documentElement;
    xmlDocument = document.getElementById("xmlframe").contentDocument;

    debug('Basics');
    debug('');

    test("document.createAttribute('x')", "Attr");
    test("document.createComment('')", "Comment");
    test("document.createDocumentFragment()", "DocumentFragment");
    test("document.implementation", "DOMImplementation");
    test("root.attributes", "NamedNodeMap");
    test("document.createNodeIterator(root, 0, null, false)", "NodeIterator");
    test("document.getElementsByTagName('div')", "HTMLCollection");
    test("document.createRange()", "Range");
    test("document.createTextNode('')", "Text");
    test("document.createTreeWalker(root, 0, null, false)", "TreeWalker");

    debug('');
    debug('XML');
    debug('');

    test("xmlDocument", "XMLDocument");
    test("xmlDocument.createCDATASection('')", "CDATASection");
    test("xmlDocument.createElementNS('x', 'x', 'x')", "Element");
    test("xmlDocument.createProcessingInstruction('x', '')", "ProcessingInstruction");

    debug('');
    debug('Events');
    debug('');

    test("document.createEvent('Event')", "Event");
    test("document.createEvent('KeyboardEvent')", "KeyboardEvent");
    test("document.createEvent('MouseEvent')", "MouseEvent");
    test("document.createEvent('MutationEvent')", "MutationEvent");
    test("document.createEvent('TextEvent')", "TextEvent");
    test("document.createEvent('UIEvent')", "UIEvent");
    test("document.createEvent('WheelEvent')", "WheelEvent");

    debug('');
    debug('CSS DOM');
    debug('');

    test("document.styleSheets", "StyleSheetList");
    test("stylesheet", "CSSStyleSheet");
    test("stylesheet.cssRules", "CSSRuleList");
    test("stylesheet.cssRules.item(0)", "CSSStyleRule");
    test("stylesheet.cssRules.item(0).style", "CSSStyleDeclaration");
    test("stylesheet.media", "MediaList");

    debug('');
    debug('XPath');
    debug('');

    test("document.createExpression('//*', document.createNSResolver(document))", "XPathExpression");
    test("document.evaluate('//*', document, document.createNSResolver(document), 0, null)", "XPathResult");

    debug('');
    debug('Other');
    debug('');

    test("window", "Window");

    debug('');
    debug('HTML DOM');
    debug('');

    test("root.children", "HTMLCollection");
    test("document", "HTMLDocument");
    test("document.createElement('select').options", "HTMLOptionsCollection");

    debug('');
    debug('HTML Elements');
    debug('');

    testTag("a", "HTMLAnchorElement");
    testTag("abbr", "HTMLElement");
    testTag("acronym", "HTMLElement");
    testTag("address", "HTMLElement");
    testTag("area", "HTMLAreaElement");
    testTag("article", "HTMLElement");
    testTag("aside", "HTMLElement");
    testTag("b", "HTMLElement");
    testTag("base", "HTMLBaseElement");
    testTag("basefont", "HTMLElement");
    testTag("bdo", "HTMLElement");
    testTag("bgsound", "HTMLUnknownElement");
    testTag("big", "HTMLElement");
    testTag("blockquote", "HTMLQuoteElement");
    testTag("body", "HTMLBodyElement");
    testTag("br", "HTMLBRElement");
    testTag("button", "HTMLButtonElement");
    testTag("canvas", "HTMLCanvasElement");
    testTag("caption", "HTMLTableCaptionElement");
    testTag("center", "HTMLElement");
    testTag("cite", "HTMLElement");
    testTag("code", "HTMLElement");
    testTag("col", "HTMLTableColElement");
    testTag("colgroup", "HTMLTableColElement");
    testTag("dd", "HTMLElement");
    testTag("del", "HTMLModElement");
    testTag("dfn", "HTMLElement");
    testTag("dir", "HTMLDirectoryElement");
    testTag("div", "HTMLDivElement");
    testTag("dl", "HTMLDListElement");
    testTag("dt", "HTMLElement");
    testTag("em", "HTMLElement");
    testTag("embed", "HTMLEmbedElement");
    testTag("fieldset", "HTMLFieldSetElement");
    testTag("font", "HTMLFontElement");
    testTag("footer", "HTMLElement");
    testTag("form", "HTMLFormElement");
    testTag("frame", "HTMLFrameElement");
    testTag("frameset", "HTMLFrameSetElement");
    testTag("head", "HTMLHeadElement");
    testTag("h1", "HTMLHeadingElement");
    testTag("h2", "HTMLHeadingElement");
    testTag("h3", "HTMLHeadingElement");
    testTag("h4", "HTMLHeadingElement");
    testTag("h5", "HTMLHeadingElement");
    testTag("h6", "HTMLHeadingElement");
    testTag("head", "HTMLHeadElement");
    testTag("header", "HTMLElement");
    testTag("hgroup", "HTMLElement");
    testTag("hr", "HTMLHRElement");
    testTag("html", "HTMLHtmlElement");
    testTag("i", "HTMLElement");
    testTag("iframe", "HTMLIFrameElement");
    testTag("image", "HTMLUnknownElement");
    testTag("img", "HTMLImageElement");
    testTag("input", "HTMLInputElement");
    testTag("ins", "HTMLModElement");
    testTag("kbd", "HTMLElement");
    testTag("label", "HTMLLabelElement");
    testTag("layer", "HTMLElement");
    testTag("legend", "HTMLLegendElement");
    testTag("li", "HTMLLIElement");
    testTag("link", "HTMLLinkElement");
    testTag("listing", "HTMLPreElement");
    testTag("main", "HTMLElement");
    testTag("map", "HTMLMapElement");
    testTag("marquee", "HTMLMarqueeElement");
    testTag("menu", "HTMLMenuElement");
    testTag("meta", "HTMLMetaElement");
    testTag("nav", "HTMLElement");
    testTag("nobr", "HTMLElement");
    testTag("noembed", "HTMLElement");
    testTag("noframes", "HTMLElement");
    testTag("nolayer", "HTMLElement");
    testTag("noscript", "HTMLElement");
    testTag("object", "HTMLObjectElement");
    testTag("ol", "HTMLOListElement");
    testTag("optgroup", "HTMLOptGroupElement");
    testTag("option", "HTMLOptionElement");
    testTag("p", "HTMLParagraphElement");
    testTag("param", "HTMLParamElement");
    testTag("plaintext", "HTMLElement");
    testTag("pre", "HTMLPreElement");
    testTag("q", "HTMLQuoteElement");
    testTag("rp", "HTMLElement");
    testTag("rt", "HTMLElement");
    testTag("ruby", "HTMLElement");
    testTag("s", "HTMLElement");
    testTag("samp", "HTMLElement");
    testTag("script", "HTMLScriptElement");
    testTag("section", "HTMLElement");
    testTag("select", "HTMLSelectElement");
    testTag("small", "HTMLElement");
    testTag("span", "HTMLSpanElement");
    testTag("strike", "HTMLElement");
    testTag("strong", "HTMLElement");
    testTag("style", "HTMLStyleElement");
    testTag("sub", "HTMLElement");
    testTag("sup", "HTMLElement");
    testTag("table", "HTMLTableElement");
    testTag("tbody", "HTMLTableSectionElement");
    testTag("td", "HTMLTableCellElement");
    testTag("textarea", "HTMLTextAreaElement");
    testTag("tfoot", "HTMLTableSectionElement");
    testTag("th", "HTMLTableCellElement");
    testTag("thead", "HTMLTableSectionElement");
    testTag("title", "HTMLTitleElement");
    testTag("tr", "HTMLTableRowElement");
    testTag("tt", "HTMLElement");
    testTag("u", "HTMLElement");
    testTag("ul", "HTMLUListElement");
    testTag("var", "HTMLElement");
    testTag("wbr", "HTMLElement");
    testTag("xmp", "HTMLPreElement");

    // Not yet tested:

    // CSSFontFaceRule
    // CSSImportRule
    // CSSMediaRule
    // CSSPageRule
    // CSSRule
    // WebKitCSSKeyframeRule
    // WebKitCSSKeyframesRule
    // SVGColor
    // SVGPaint
    // SVGZoomEvent

    // Conditional elements, VIDEO, RUBY.

    // the various window sub-objects

    // what else is missing?

    if (window.testRunner)
        testRunner.notifyDone();
}

function frameLoaded()
{
    runTest();
}

</script>
<iframe id="xmlframe" onload="frameLoaded()" style="height:0px" src="resources/xmldoc.xml"></iframe>
</body>
</html>
